#!/usr/bin/env python
#coding=utf-8
import socket

messages = ["this is a message", 'have a joke', 'have a beer']

server = ('127.0.0.1', 10001)

list_socket = []

for i in  xrange(10):
	s = socket.socket()
	s.connect(server)
	list_socket.append(s)

for m in messages:

	for i, s in enumerate(list_socket):
		"""通过enumerate返回tuple"""
		s.send('%s counter %s' %(m, i+1))
		print 'send %s counter %s' %(m, i+1)

	for i, s in enumerate(list_socket):
		buf = s.recv(1024)
		if buf:
			print 'recv', buf, i+1
		else:
			print 'server is closed'
			s.close()
